/**
 * TabVD is a Virtual Desktop Client/Server designed specifically for connecting
 * from Tablet like devices.
 *
 * Copyright (C) 2011 Subhabrata Ghosh
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * LogUtils.java
 *
 *  Created on: Jul 21, 2011
 *      Author: subhagho
 */
package net.langene.tabvd.core;

/**
 * @author subhagho
 * 
 */
public class LogUtils {
	public static String getStackTrace(Throwable ex) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("Exception : ").append(ex.getClass().getCanonicalName())
				.append(":").append(ex.getLocalizedMessage()).append("\n");
		StackTraceElement[] stes = ex.getStackTrace();
		if (stes != null && stes.length > 0) {
			for (StackTraceElement ste : stes) {
				buffer.append("\tat ").append(ste.getClassName()).append(".")
						.append(ste.getMethodName());
				buffer.append("(").append(ste.getFileName()).append(":")
						.append(ste.getLineNumber()).append(")\n");
			}
		}
		if (ex.getCause() != null) {
			buffer.append("============================================================================");
			buffer.append(getStackTrace(ex.getCause()));
			buffer.append("============================================================================");
		}
		return buffer.toString();
	}
}
